<? 
	$base_url = 'http://stanford.edu/~rehlers/cgi-bin/mandi/webservice?action=';
	$test = $_GET['test'];
	
	switch($test){
		case 'newpublickey':
			newpublickey($base_url);
			break;
		case 'update':
			update($base_url);
			break;
		case 'submit':
			submit($base_url);
			break;
		default:
			break;
	}
	
	function submit($base_url){
	
		$data = array(
			'employee' => $_GET['id'],
			'sold' => time(),
			'entry_id' => '1.1.2011-05-10 18:57:42',
			'toll' => 33,
			'seller_license' => 35,
			'buyer_license' => 26,
			'produce_id' => 1,
			'weight' => 1,
			'rate' => 3.1, //amount, not percentage, for all following
			'comm_comm_agent' => .1
		);
		$url = $base_url.'submit';
		
		$data_string;
		foreach($data as $key=>$value) { $data_string .= $key.'='.$value.'&'; }
		rtrim($data_string,'&');

		$ch = curl_init();

		//set the url, number of POST vars, POST data
		curl_setopt($ch,CURLOPT_URL,$url);
		curl_setopt($ch,CURLOPT_POST,count($data));
		curl_setopt($ch,CURLOPT_POSTFIELDS,$data_string);

		//execute post
		$result = curl_exec($ch);

		//close connection
		curl_close($ch);
	}
	
	function update($base_url){
		$url = $base_url.'update&lastupdate='.$_GET['lastupdate'].'&id='.$_GET['id'];
		$ch = curl_init();

		//set the url, number of POST vars, POST data
		curl_setopt($ch,CURLOPT_URL,$url);

		//execute post
		$result = curl_exec($ch);

		//close connection
		curl_close($ch);
	}
	
	function newpublickey($base_url){
		//newpublickey   pub:1817047:17   priv:1817047:106721  from http://www.langenhoven.com/code/emailencrypt/keygen.php
		$key = $_GET['key'];
		
		$url = 'http://stanford.edu/~rehlers/cgi-bin/mandi/webservice?action=newpublickey';
		$data = array(
			'key'=>$key,
			'name'=>'Bob',
			'addr_street'=>'123 Street',
			'addr_state'=>'New Delhi',
			'addr_pincode'=>'666');
		$data_string;
		foreach($data as $key=>$value) { $data_string .= $key.'='.$value.'&'; }
		rtrim($data_string,'&');

		$ch = curl_init();

		//set the url, number of POST vars, POST data
		curl_setopt($ch,CURLOPT_URL,$url);
		curl_setopt($ch,CURLOPT_POST,count($data));
		curl_setopt($ch,CURLOPT_POSTFIELDS,$data_string);

		//execute post
		$result = curl_exec($ch);

		//close connection
		curl_close($ch);
	}
?>